package com.example.demo.Controller;


import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/message")
public class MessageController {

    private List<MessageInfo> messageInfos = new ArrayList<>();

    @RequestMapping("/publish")
    public Boolean publish(MessageInfo  messageInfo){
        //看日志，咋看？在方法的第一行加上日志：
        System.out.println("接收参数，messageInfo:"+messageInfo);
        //1，参数校验
        //2:存储数据，暂时存储在内存中
        if(!StringUtils.hasLength(messageInfo.getFrom()) ||
                !StringUtils.hasLength(messageInfo.getTo()) ||
                !StringUtils.hasLength(messageInfo.getSay())){
            return false;
        }
        messageInfos.add(messageInfo);
        return true;
    }

    //获取留言信息:
    @RequestMapping("/getList")
    public List<MessageInfo>  getList(){
        return messageInfos;
    }
}
